package com.example.github.jdbc;

import java.sql.*;

public class JDBCDemo {
    public static void main(String[] args) throws ClassNotFoundException {
        String url = "jdbc:mysql://127.0.0.1:3306/mall";
        String userName = "root";
        String password = "123456";
        try {
            // 创建连接
            Connection connection = DriverManager.getConnection(url, userName, password);
            String sql = "select * from ums_role";
            // 获取预编执行器
            Statement statement = connection.createStatement();
            // 执行sql
            ResultSet resultSet = statement.executeQuery(sql);
            System.out.println(resultSet);
            statement.close(); // 由里到外释放资源
            connection.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
